package com.maiji.cloud.controller;

import com.maiji.cloud.entities.community.ComComment;
import com.maiji.cloud.entities.community.ComMsgInfo;
import com.maiji.cloud.request.BaseDataReqDto;
import com.maiji.cloud.request.BaseInputDto;
import com.maiji.cloud.request.IdInputDto;
import com.maiji.cloud.request.ReqMetaData;
import com.maiji.cloud.request.community.ComCommentMsgInputDto;
import com.maiji.cloud.response.BaseMetaResDto;
import com.maiji.cloud.response.BaseOutPutDto;
import com.maiji.cloud.response.BaseResDto;
import com.maiji.cloud.response.community.ComCommentOutputDto;
import com.maiji.cloud.response.shopingmall.FinancialDetailsResData;
import com.maiji.cloud.service.ComCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

@RestController
@RequestMapping("/community")
@Api(value = "论坛模块")
public class ComCommentController {

    @Autowired
    ComCommentService commentService;

    /**
     *
     * 社区评论通用接口
     * @param inputDto
     * @param maijiToken
     * @return
     */
    @ApiOperation("社区评论通用接口")
    @PostMapping("/comment")
    public BaseOutPutDto<FinancialDetailsResData> comment(@RequestBody BaseInputDto<ComCommentMsgInputDto>inputDto, @RequestHeader("maijiToken")String maijiToken){
        return commentService.comment(inputDto,maijiToken);
    }

    /**
     * 评论动态
     * @param inputDto
     * @param maijiToken
     * @return
     */
    @ApiOperation("评论动态")
    @PostMapping("/commentMsg")
    public BaseOutPutDto<FinancialDetailsResData>commentMsg(@RequestBody BaseInputDto<ComCommentMsgInputDto> inputDto, @RequestHeader("maijiToken")String maijiToken){
        return commentService.commentMsg(inputDto,maijiToken);
    }

    /**
     * 转发动态
     * @param inputDto
     * @param maijiToken
     * @return
     */
    @ApiOperation("转发动态")
    @PostMapping("/transmitMsg")
    public BaseOutPutDto<FinancialDetailsResData>transmitMsg(@RequestBody BaseInputDto<ComCommentMsgInputDto>inputDto,@RequestHeader("maijiToken")String maijiToken){
        return commentService.transmitMsg(inputDto,maijiToken);
    }

    /**
     * 评论其它评论
     * @param inputDto
     * @param maijiToken
     * @return
     */
    @ApiOperation("评论其它评论")
    @PostMapping("/commentComment")
    public BaseOutPutDto<FinancialDetailsResData>commentComment(@RequestBody BaseInputDto<ComCommentMsgInputDto> inputDto,@RequestHeader("maijiToken")String maijiToken){
        return commentService.commentComment(inputDto,maijiToken);
    }

    /**
     * 评论回复
     * @param inputDto
     * @param maijiToken
     * @return
     */
    @ApiOperation("评论回复")
    @PostMapping("/commentReply")
    public BaseOutPutDto<FinancialDetailsResData>commentReply(@RequestBody BaseInputDto<ComCommentMsgInputDto>inputDto,@RequestHeader("maijiToken")String maijiToken){
        return commentService.commentReply(inputDto,maijiToken);
    }

    /**
     * 评论列表
     * @param inputDto
     * @param maijiToken
     * @return
     */
    @ApiOperation("评论列表")
    @PostMapping("/commentList")
    public BaseOutPutDto<List<ComCommentOutputDto>>commentList( @RequestBody BaseInputDto<IdInputDto>inputDto, @RequestHeader("maijiToken")String maijiToken){

        return commentService.commentList(inputDto,maijiToken);
    }

    @ApiOperation("评论点赞")
    @PostMapping("/commentPraise")
    public BaseOutPutDto<String>commentPraise(@RequestBody BaseInputDto<IdInputDto>inputDto,@RequestHeader("maijiToken")String maijiToken){

        return commentService.commentPraise(inputDto,maijiToken);

    }
    /**
     * 取消评论点赞
     * @param inputDto
     * @param maijiToken
     * @return
     */
    @ApiOperation("取消评论点赞")
    @PostMapping("/cancelCommentPraise")
    public BaseOutPutDto<String> cancelCommentPraise(@RequestBody BaseInputDto<IdInputDto>inputDto,@RequestHeader("maijiToken")String maijiToken){

        return commentService.cancelCommentPraise(inputDto,maijiToken);
    }

    @ApiOperation("评论删除 用于前端")
    @PostMapping("/commentdelete")
    public BaseOutPutDto<String> commentdelete(@RequestBody BaseInputDto<IdInputDto>inputDto,@RequestHeader("maijiToken")String maijiToken){

        return commentService.commentdelete(inputDto,maijiToken);
    }

    @ApiOperation("评论删除 用于管理平台")
    @PostMapping("/commentManageDelete")
    public BaseOutPutDto<String> commentManageDelete(@RequestBody BaseInputDto<IdInputDto>inputDto){

        return commentService.commentManageDelete(inputDto);
    }

    /**
     * 获取动态列表 - 评论统计 - pc
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("/findAllMsgs")
    public BaseMetaResDto<List<ComMsgInfo>> findAllMsgs (@RequestBody BaseDataReqDto<ComMsgInfo> baseDataReqDto) {
        ComMsgInfo data = baseDataReqDto.getData();
        ReqMetaData metaData = baseDataReqDto.getMetaData();
        return commentService.findAllMsgs(data.getNickName(), data.getTitle(), data.getContent(), metaData);
    }

    /**
     * 获取动态的评论列表 - pc
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("/findAllComments")
    public BaseMetaResDto<List<ComComment>> findAllComments (@RequestBody BaseDataReqDto<ComComment> baseDataReqDto) {
        String msgId = baseDataReqDto.getData().getMsgId();
        Integer read_already = baseDataReqDto.getData().getReadAlready();
        Integer delete = baseDataReqDto.getData().getDelete();
        String nickName = baseDataReqDto.getData().getNickName();
        String content = baseDataReqDto.getData().getContent();
        ReqMetaData metaData = baseDataReqDto.getMetaData();
        return commentService.findAllComments(msgId, read_already, delete, nickName, content, metaData);
    }

    /**
     * 读取审核评论 - pc
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("/readComment")
    public BaseResDto readComment (@RequestBody BaseDataReqDto<List<ComComment>> baseDataReqDto) {
        List<ComComment> comComments = baseDataReqDto.getData();
        return commentService.readComment(comComments);
    }

}

